import type { App, Component } from "vue";
// @ts-ignore
const modules: Record<string, { default: Component }> =  import.meta.glob("./**/**.{vue,ts,tsx}", { eager: true });

function getComponentNameTranToUpperCase(path:string) {
    const paths = path.replace(".vue", "").split("/")
    return paths[paths.length-1].toLowerCase().replace(/\b(\w+)\b/g, function(word) {
        return word.replace(word[0], word[0].toUpperCase());
    }).replace("-","");
}

const  install =  (app: App) => {
    Object.entries(modules).forEach(([path, { default: component}])=>{
        const name = getComponentNameTranToUpperCase(path);
        app.component(component.name || name, component);
    })
}

export default {
    install
};